namespace QMVnSoft.Opening
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCDSLister : FormOpenningLister
    {
        private IContainer components;
        private CDSDataAccess oMethod;

        public FormCDSLister()
        {
            this.oMethod = new CDSDataAccess();
            this.InitializeComponent();
            this.OnRefresh();
        }

        public FormCDSLister(bool pb_CheckDetailMost, bool pb_WithoutParent) : base(pb_CheckDetailMost, pb_WithoutParent)
        {
            this.oMethod = new CDSDataAccess();
            this.InitializeComponent();
            this.OnRefresh();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x31a, 0x214);
            base.Name = "FormCDSLister";
            this.Text = "Số dư đầu kỳ công trình đầu kỳ";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override void OnAdd()
        {
            if (AppInstance.EndingDateOfSubEnterprice >= AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                base.LocalFormEditor = new FormCDSEditor();
                base.OnAdd();
            }
        }

        protected override void OnDelete()
        {
            if (AppInstance.EndingDateOfSubEnterprice >= AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if ((base.DataGridBrowser.CurrentRow != null) && (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                if ((base.DataGridBrowser.SelectedRows != null) && (base.DataGridBrowser.SelectedRows.Count != 0))
                {
                    foreach (DataGridViewRow row in base.DataGridBrowser.SelectedRows)
                    {
                        DataRow row2 = ((DataRowView) row.DataBoundItem).Row;
                        if (this.oMethod.Delete(row2["Stt"]))
                        {
                            base.LocalTable.Rows.Remove(row2);
                        }
                    }
                }
                else
                {
                    DataRow row3 = ((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row;
                    if (this.oMethod.Delete(row3["Stt"]))
                    {
                        base.LocalTable.Rows.Remove(row3);
                    }
                }
                base.LocalTable.AcceptChanges();
            }
        }

        protected override void OnEdit()
        {
            if (AppInstance.EndingDateOfSubEnterprice >= AppInstance.OpeningDateOfSubEnterprice)
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                base.LocalFormEditor = new FormCDSEditor();
                base.OnEdit();
            }
        }

        protected override void OnGenerateColumns()
        {
            object[][] objArray = new object[8][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Ma_Sp";
            objArray2[1] = "Công trình";
            objArray2[2] = "C";
            objArray[0] = objArray2;
            object[] objArray3 = new object[4];
            objArray3[0] = "Ten_Sp";
            objArray3[1] = "Tên công trình";
            objArray3[2] = "C";
            objArray[1] = objArray3;
            object[] objArray4 = new object[4];
            objArray4[0] = "Tk";
            objArray4[1] = "Tài khoản";
            objArray4[2] = "C";
            objArray[2] = objArray4;
            object[] objArray5 = new object[4];
            objArray5[0] = "Tk_Du";
            objArray5[1] = "Tk đối ứng";
            objArray5[2] = "C";
            objArray[3] = objArray5;
            object[] objArray6 = new object[4];
            objArray6[0] = "Ma_Dt";
            objArray6[1] = "Đối tượng";
            objArray6[2] = "C";
            objArray[4] = objArray6;
            object[] objArray7 = new object[4];
            objArray7[0] = "Ma_Vt";
            objArray7[1] = "Vật tư";
            objArray7[2] = "C";
            objArray[5] = objArray7;
            objArray[6] = new object[] { "So_Luong", "Số lượng", "N", AppInstance.TextNumericFormat.Quantity };
            objArray[7] = new object[] { "Tien", "Giá trị", "N", AppInstance.TextNumericFormat.LocalAmount };
            base.LocalColNames = objArray;
            base.OnGenerateColumns();
        }

        protected override void OnRefresh()
        {
            base.LocalTable = this.oMethod.GetDataTable(AppInstance.Subsidiary);
            base.OnRefresh();
        }
    }
}

